<?php
require("libraries/student.php");
class Agency extends Student{
    public function __construct(){
        parent::__construct();
		$this->load->helper(array("form"));
        $this->load->library("form_validation");
        $this->load->model("model_agency");
        $this->load->library("string");
    }
    public function index(){
        $data['error'] = "";
        $data['data'] = "";
        $data['title'] = "Manage cruises of agency";
        $data['template'] = "agency/add";
        $data['act'] = 2;
		$data['listages'] = $this->model_agency->listall();
        $data['listcrui'] = $this->model_agency->listcrui();
        $this->load->view("layout",$data);
    }
	public function getcruise(){
		$user_id = $_POST['userid'];
		$data = $this->model_agency->getcruise($user_id);
		echo '<table cellpadding="0" cellspacing="0" width="905">
			<tbody><tr>
			  <th width="23" style="border-top:1px solid #CCC;border-left:1px solid #CCC">Stt.</th>
			  <th width="185" style="border-top:1px solid #CCC">Agency name</th>
			  <th width="200" style="border-top:1px solid #CCC">Cruise name</th>
			  <th width="90" style="border-top:1px solid #CCC">Agency id</th>
			  <th width="90" style="border-top:1px solid #CCC">Cruise id</th>
			  <th width="180" style="border-top:1px solid #CCC">Created</th>
			  <th width="86" style="border-top:1px solid #CCC">Actions</th>
			</tr>';
		if($data != NULL){
			$stt = 1;
			foreach($data as $items){
				echo "<tr>";
				echo "<td>".$stt."</td>";
				echo "<td>".$items['agency_name']."</td>";
				echo "<td>".$items['cruises_name']."</td>";
				echo "<td>".$items['agency_id']."</td>";
				echo "<td>".$items['cruises_id']."</td>";
				echo "<td>".$items['agecr_time']."</td>";
				echo "<td>";
				echo "<div class='actions_menu'><ul>";
		?>
					<li><a href="javascript:void(0)" class="delete" rel="<?php echo $items['agecr_id']; ?>">Del</a></li>
        <?php
				echo "</ul></div>";
				echo "</td>";
				echo "</tr>";
				$stt++;
			}
		}else{
			echo "<tr>";
			echo "<td colspan='8'>No data</td>";
			echo "</tr>";
		}
		echo "</tbody></table>";
	}
	public function addcruise(){
		$agency = $_POST['agency'];
		$cruise = $_POST['cruise'];
		$aname  = $_POST['aname'];
		$cname  = $_POST['cname'];
		$this->model_agency->add($agency,$cruise,$aname,$cname);
		$data = $this->model_agency->getcruise($agency);
		echo '<table cellpadding="0" cellspacing="0" width="905">
			<tbody><tr>
			  <th width="23" style="border-top:1px solid #CCC;border-left:1px solid #CCC">Stt.</th>
			  <th width="185" style="border-top:1px solid #CCC">Agency name</th>
			  <th width="200" style="border-top:1px solid #CCC">Cruise name</th>
			  <th width="90" style="border-top:1px solid #CCC">Agency id</th>
			  <th width="90" style="border-top:1px solid #CCC">Cruise id</th>
			  <th width="180" style="border-top:1px solid #CCC">Created</th>
			  <th width="86" style="border-top:1px solid #CCC">Actions</th>
			</tr>';
		if($data != NULL){
			$stt = 1;
			foreach($data as $items){
				echo "<tr>";
				echo "<td>".$stt."</td>";
				echo "<td>".$items['agency_name']."</td>";
				echo "<td>".$items['cruises_name']."</td>";
				echo "<td>".$items['agency_id']."</td>";
				echo "<td>".$items['cruises_id']."</td>";
				echo "<td>".$items['agecr_time']."</td>";
				echo "<td>";
				echo "<div class='actions_menu'><ul>";
		?>
					<li><a href="javascript:void(0)" class="delete" rel="<?php echo $items['agecr_id']; ?>">Del</a></li>
        <?php
				echo "</ul></div>";
				echo "</td>";
				echo "</tr>";
				$stt++;
			}
		}else{
			echo "<tr>";
			echo "<td colspan='8'>No data</td>";
			echo "</tr>";
		}
		echo "</tbody></table>";
	}
    public function del(){
        $id = $_POST['id'];
        $this->model_agency->del($id);
    }
}